package cn.lecosa.spark.test;

/**
1.如果字符串最后一位有值，则没有区别，
2.如果最后n位都是切割符，split(" ")不会继续切分，split(" ", -1)会继续切分
*/
public class StringSplit {
	public static void main(String[] args) {
		  String line = "a b  c    ";      // 1
		  String str = "a b c      d";     // 2
		  String [] tmp = line.split(" ");  
  System.out.println(tmp.length+"------");  
 	  for(int i=0;i<tmp.length;i++){  
		      System.out.println(i+"="+tmp[i]);  
		  }  
		    
	  String [] items = line.split(" ",-1);  
		  System.out.println(items.length+"========");  
		  for(int i=0;i<items.length;i++){  
		      System.out.println(i+"="+items[i]);  
		  } 
	   
		  System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
		  
		  tmp = str.split(" ");  
		  System.out.println(tmp.length+"------");  
		  for(int i=0;i<tmp.length;i++){  
		      System.out.println(i+"="+tmp[i]);  
		  }  
		    
		  items = str.split(" ",-1);  
		  System.out.println(items.length+"========");  
		  for(int i=0;i<items.length;i++){  
		      System.out.println(i+"="+items[i]);  
		  } 
	}
}
